function fdnoise(AN,D,M)
% fdnoise(AN,D,M)
% 	Parameters:
% 		AN:	number of points to be used in the time series to be shifted by this function
% 			NOTE:  this is approximately twice the number that will be generated for the 
% 			inital sequence of complex numbers in the Fourier domain.
% 		D:	inital displacement
% 		M:	length of the kernel
% 
% 	Outputs:
% 		The only output of this function are the plots described below.
% 	
% 	Purpose of this code:  This code is designed to geneate a sequence of points in the Fourier Domain
% 		of length AN/2 that have complex values whose real and imaginary coefficients are chosen
% 		randomly from a set with a normal distribution with a mean of 1 and a variance of 1.
% 		This function then, after appropriate formating, converts this sequence to the time
% 		domain using the matlab ifft function,  This time sequence is then displaced by D units and
% 		returned to the Fourier domain via the matlab fft function.  The power spectrum is calculated
% 		for the resutling sequence and then compared to the power spectrum of the original sequence.
% 		the fractional error of this comparision is then plotted.
hold off;

%% establish variables
LB = floor(D + (M-1)./2);
SHFTD = floor(D);
if (mod(LB,2) == 1)
    LB = LB + 1;
    SHFTD = SHFTD + 1;
end
N = AN + LB;
x = 1:AN;
H = AN./2;

%% generate noise
a = random('norm',0,1,1,H-1);
b = random('norm',0,1,1,H-1);

c = a+b.*i;
k = fliplr(conj(c));

%% generate sequence to introduce to ifft
s = [0 c 0 k];
s = s.*(sqrt((N-1)./2));

%% IFFT from FD to TD
ts = ifft(s);

%% Plot Power Spectrum of Original Dataset
ps = (c.*conj(c));
xps = 1:(H-1);
%plot(xps,ps,'b');
%hold on;

%% Plot Shifted Time Sequence (Interpolation)
tail = zeros(1,SHFTD);
ats = [ts tail];
sts = FDtest(ats,D,M);
ststr = sts(SHFTD+1:end);

stsf = fft(ststr);
pss = (stsf.*conj(stsf))./((N-1)./2);

psss = fftshift(pss);
b = floor((AN+2)./2);
pssst = psss((b+1):AN);
plot(xps,pssst,'r');

err = abs(ps - pssst);%.\abs(ps);
%plot(xps,err,'g');
semilogy(xps,err,'b');



end